<template>
  <div class="servicePageOrderList padding_20">
    <el-input v-model="param.name"
              placeholder="请输入产品名称"
              class="w-200"
              @clear="handleQuery"
              clearable />
    <el-button type="primary"
               @click="handleQuery">查 询</el-button>
    <el-button type="primary"
               @click="addNew(param)">新 增</el-button>
    <Table :columns="tableCol"
           :data="tableData"
           :loading="loading"
           stripe
           border
           class="mt-20">
      <template slot-scope="{row,index}"
                slot="action">
        <span @click="addNew(row)">编辑</span>
        <span @click="del(row)">删除</span>
      </template>
    </Table>
    <page @getList="_getList"
          :pageTotal="pageTotal"
          ref="page"></page>
  </div>
</template>

<script>
  export default {
    name: "digitalProductsList",
    data () {
      return {
        tableCol: [
          {
            type: 'index',
            title: '',
            width: 60,
            render: (h, params) => {
              return h('span', params.index);
            }
          },
          {
            title: '名称',
            key: 'name',
            render: (h, params) => {
              return h('span', params.row.name);
            }
          },
          {
            title: '创建时间',
            key: 'createTime',
            width: 150,
            render: (h, params) => {
              return h('span',
                this.commonFunction.timestampFormat(new Date(params.row.createTime), 'yyyy-MM-dd hh:mm'));
            }
          },
          {
            title: '操作',
            slot: 'action',
            align: 'center'
          }
        ],
        tableData: [],
        pageTotal: 0,       //总条数
        loading: false,
        param: {
          name: ''
        },
      }
    },
    mounted () {
      this._getList();
    },
    methods: {
      _getList () {
        this.loading = true;
        this.post(this.api.digitalProducts.digitalProductsList, this.param).then((res) => {
          if (res.data.code === '200') {
            this.loading = false;
            this.tableData = res.data.object;
            this.pageTotal = this.tableData.length;
          }
        })
      },
      addNew (row) {
        this.$router.push({ name: 'editDigitalProductView', query: { id: row.id } })
      },
      del (row) {
        this.$Modal.confirm({
          title: '确定',
          content: '<p>您确定修改密码？</p>',
          onOk: () => {
            this.post(this.api.digitalProducts.deleteDigitalProducts, { id: row.id }).then((res) => {
              if (res.data.code === '200') {
                this.$Message.success('删除成功');
                this._getList();
              } else {
                this.$Message.error(data.message);
              }
            })
          },
          onCancel: () => {
          }
        });
      },
      handleQuery () {
        this._getList();
      }
    }
  }
</script>

<style scoped>
</style>
